//
//  RightTableView.m
//  分类列表联动
//
//  Created by zl on 2019/9/27.
//  Copyright © 2019 yanhaiqiang. All rights reserved.
//

#import "RightTableView.h"
#import "JDCategoryLeftTableCell.h"
@interface RightTableView ()<UITableViewDelegate, UITableViewDataSource>


@end

static NSString *leftCell = @"leftCell";
@implementation RightTableView
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style Sting:(NSString *)str{
    if (self = [super initWithFrame:frame style:style]) {
        self.delegate = self;
        self.dataSource = self;
        self.rowHeight = 44;
        [self registerClass:UITableViewCell.class forCellReuseIdentifier:leftCell];
        if ([str isEqualToString:@"1"]) {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Ggtongzhi:)name:@"Ggtongzhi" object:nil];
        }else{
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhi:)name:@"tongzhi" object:nil];
        }
    }
    return self;
}
// 公共语句
- (void)Ggtongzhi:(NSNotification *)text{
    NSUserDefaults *User = [NSUserDefaults standardUserDefaults];
    // 个人组语句
    NSDictionary *dict = @{
                           @"kfUserId":[User objectForKey:@"kfId"],
                           @"PC":@"PC",
                           @"pubPriType":@"0",
                           @"groupType":@"1",
                           @"groupId":text.userInfo[@"name"]
                           };
    [HttpsTool get:@"/web/recovery/all" params:dict success:^(id response) {
//        NSLog(@"%@",response);
//        NSLog(@"%@",response[@"msg"]);
        
        InfoModel *model = [InfoModel yy_modelWithJSON:response];
        self.DataArray = [model.data.list yy_modelToJSONObject];
        [self reloadData];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
// 个人语句
- (void)tongzhi:(NSNotification *)text{
    NSUserDefaults *User = [NSUserDefaults standardUserDefaults];
    // 个人组语句
    NSDictionary *dict = @{
                           @"kfUserId":[User objectForKey:@"kfId"],
                           @"PC":@"PC",
                           @"pubPriType":@"1",
                           @"groupType":@"1",
                           @"groupId":text.userInfo[@"name"]
                           };
    [HttpsTool get:@"/web/recovery/all" params:dict success:^(id response) {
//        NSLog(@"%@",response);
//        NSLog(@"%@",response[@"msg"]);
        
        InfoModel *model = [InfoModel yy_modelWithJSON:response];
        self.DataArray = [model.data.list yy_modelToJSONObject];
        [self reloadData];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
- (NSArray *)DataArray{
    if (!_DataArray) {
        _DataArray = [[NSArray alloc]init];
    }
    return _DataArray;
}
- (void)LoadData{
    NSUserDefaults *User = [NSUserDefaults standardUserDefaults];
    NSLog(@"++++%@",self.Str);
    //    // 公共组语句
    if ([self.Str isEqualToString:@"1"]) {
        NSDictionary *dic = @{
                                @"kfUserId":[User objectForKey:@"kfId"],
                                @"PC":@"PC",
                                @"pubPriType":@"0",
                                @"groupType":@"0",
                                @"groupId":@""
                                };
            [HttpsTool get:@"/web/recovery/all" params:dic success:^(id response) {
        //        NSLog(@"----%@",response);
                NSLog(@"%@",response[@"msg"]);
            } failure:^(NSError *error) {
                NSLog(@"%@",error);
            }];
    }else{
    // 个人组语句
            NSDictionary *dict = @{
                                   @"kfUserId":[User objectForKey:@"kfId"],
                                   @"PC":@"PC",
                                   @"pubPriType":@"1",
                                   @"groupType":@"1",
                                   @"groupId":self.Str
                                   };
            [HttpsTool get:@"/web/recovery/all" params:dict success:^(id response) {
    //            NSLog(@"%@",response);
    //            NSLog(@"%@",response[@"msg"]);
                InfoModel *model = [InfoModel yy_modelWithJSON:response];
                self.DataArray = [model.data.list yy_modelToJSONObject];
                [self reloadData];
            } failure:^(NSError *error) {
                NSLog(@"%@",error);
            }];
    }

    
    
    
    if (![NSString isNULLString:self.Str]) {
        
    }
}
#pragma mark -------UITabelViewdataSource-------
- (NSInteger)numberOfSections {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.DataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:leftCell];
    NSDictionary *dic = self.DataArray[indexPath.row];
    cell.textLabel.text = dic[@"recoverContent"];
//    cell.textLabel.text = @"谷银行";
    tableView.tableFooterView = [UIView new];
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    if (self.selectedRow == indexPath.row) {
//        cell.leftLine.hidden = NO;
//    }else {
//        cell.leftLine.hidden = YES;
//    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *dict = self.DataArray[indexPath.row];
    //添加 字典，将label的值通过key值设置传递
    NSDictionary *dic = @{ @"name":dict[@"recoverContent"]
                         };
    //创建通知
    NSNotification *notification =[NSNotification notificationWithName:@"TextTongzhi" object:nil userInfo:dic];
    //通过通知中心发送通知
    [[NSNotificationCenter defaultCenter] postNotification:notification];
    
}

@end
